package com.miracle9.game;

import net.sf.json.JSON;
import net.sf.json.JSONObject;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test
{
  public static void main(String[] args)
  {
    int amount = 500;
    int a = amount&0xff;
    int b =(amount>>8)&0xff;
    System.out.println(a);
    System.out.println(b);
    String am = Integer.toHexString(a);

    String am1 = Integer.toHexString(b);
    System.out.println(am);
    System.out.println(am1);
    int byteValue = Integer.parseInt(am, 16);
    int byteValue1 = Integer.parseInt(am1, 16);


    System.out.println("byteValue="+am);
    System.out.println("byteValue1="+am1);
    int[] data = {0x0C,0x71 , 0x01, 0x07, byteValue,byteValue1,0x01 ,0x00 };
    int sum = calculateChecksum(data);
    String jym = Integer.toHexString(sum).toUpperCase();
    System.out.println(jym);
    if(jym.length() > 2){
      jym = jym.substring(jym.length()-2);
    }
    System.out.println("FA 0C 00 71 0"+1+" 07 "+"F4"+" 0"+1+" 01 00 "+jym+" FB");
  //FA 0C 00 71 01 07 32 00 01 00 48 FB
  }


/*  public static void main(String[] args)
  {
    int amount = 50;
    int a = amount&0xff;
    int b =(amount>>8)&0xff;
    System.out.println(a);
    System.out.println(b);
    String am = Integer.toHexString(a);

    String am1 = Integer.toHexString(b);
    System.out.println(am);
    System.out.println(am1);
    byte byteValue = Byte.parseByte(am, 16);
    byte byteValue1 = Byte.parseByte(am1, 16);


    System.out.println("byteValue="+am);
    System.out.println("byteValue1="+am1);
    byte[] data = {0x0C,0x71 , 0x01, 0x07, byteValue,byteValue1,0x01 ,0x00 };
    int sum = calculateChecksum1(data);
    String jym = Integer.toHexString(sum).toUpperCase();
    System.out.println(jym);
    if(jym.length() > 2){
      jym = jym.substring(jym.length()-2);
    }
    System.out.println("FA 0C 00 71 0"+1+" 07 "+"32"+" 0"+0+" 01 00 "+jym+" FB");


  }*/
  public static int calculateChecksum(int[] data) {
    int checksum = 0;
    for (int b : data) {
      checksum = checksum^b ;
    }
    return checksum;
  }

  public static int calculateChecksum1(byte[] data) {
    int checksum = 0;
    for (byte b : data) {
      checksum = checksum^b ;
    }
    return checksum;
  }
}
